layui.define(['zlContext', 'zlDynamicCondition', 'table', 'layer', 'zlConfig'], function (exports) {
    var $ = layui.$,
        zlContext = layui.zlContext,
        zlDynamicCondition = layui.zlDynamicCondition,
        table = layui.table,
        layer = layui.layer,
        zlConfig = layui.zlConfig
        var fileresTable,
            isloadsearch = false,
            zlPopSourceForm = {};
    layui.event('WM_USERDEF', zlConfig.global.WM_USERDEF.WM_DRAW, null, function (WParam) {
        if (WParam && $(WParam.elem).attr('class') && $(WParam.elem).attr('class').indexOf('zlPopSourceForm') >= 0) {
            zlPopSourceForm.render($(WParam.elem), $(WParam.elem).value, $(WParam.elem).attr('text'));
        }
    });
    zlPopSourceForm = {
        $parentelem:undefined,
        render: function ($elem, value, text) {
            var showvalue = (value == undefined ? ($elem.attr('value') == undefined ? "" : $elem.attr('value')) : value);
            if ($elem.attr('loaded') && ($elem.attr('value') == undefined ? "" : $elem.attr('value')) == showvalue) {
                return;
            }
            zlPopSourceForm.$parentelem  = $elem;
            var checkboxType = []
            , radioType =[];
            checkboxType = [
                [{
                        type: 'numbers',
                        fixed: 'left',
                        title: '#'
                    },
                    {
                        type: 'checkbox',
                        fixed: 'left'
                    },
                    {
                        field: 'OBJNAME',
                        title: '名称',
                        width: 200
                    },
                    {
                        field: 'OBJCODE',
                        title: '编号',
                        width: 200
                    }]
                ]
            radioType = [   
                [{
                        type: 'numbers',
                        fixed: 'left',
                        title: '#'
                    },
                    {
                        type: 'radio',
                        fixed: 'left'
                    },
                    {
                        field: 'OBJNAME',
                        title: '名称',
                        width: 200
                    },
                    {
                        field: 'OBJCODE',
                        title: '编号',
                        width: 200
                    }]
                ]
            var defaultsetting = {
                    coltitle: checkboxType,
                    multselect: false,
                    page: false,
                    limit: 999,
                    id: 'RWID',
                    name: 'OBJNAME',
                    type: 'text',
                    edittype: 'edit',
                    isDynamic: true,
                    selectcallback: function (data, options) {
                        if (data == undefined) {
                            return;
                        }
                        if (!options.multselect) {
                            $('input[name="' + options.inputhiddename + '"]').val(data[0][options.id]);

                            if (options.type == 'text') {
                                $('input[name="' + options.inputname + '"]').val(data[0][options.name]);
                            } else if (options.type == 'image') {

                                if ($('input[name="' + options.inputname + '"]').length > 0) {
                                    var $parent = $('input[name="' + options.inputname + '"]').parent();
                                    $('input[name="' + options.inputname + '"]').remove();
                                    var html = '<img class="layui-img" name="' + options.inputname + '" src="' + layui.cache['contentPath'] + data[0][options.name] + '">';
                                    $parent.prepend(html);
                                } else {
                                    $('img[name="' + options.inputname + '"]').attr('src', layui.cache['contentPath'] + data[0][options.name]);
                                }
                            }
                        } else {
                            var id = "",
                                name = "";
                            for (var i = 0; i < data.length; i++) {
                                id = id + "," + data[i][options.id];
                                name = name + "," + data[i][options.name];
                            }
                            id = id.substr(1, id.length);
                            name = name.substr(1, name.length);
                            $('input[name="' + options.inputhiddename + '"]').val(id);
                            $('input[name="' + options.inputname + '"]').val(name);
                        }
                    },
                },
                name = $elem.attr('name'),
                inputname = 'input' + name,
                divname = 'div' + name,
                inputhiddename = name,
                $parent = $elem.parent(),
                options = ($elem.attr('settings') != "" ? eval('(' + $elem.attr('settings') + ')') : {}),
                url = options.dataurl,
                sourcedata = options.sourcedata,
                newoptions, 
                tempverify = $elem.attr('verify') == undefined ? "" : $elem.attr('verify'),
                addspanid = name + 'addspan',
                delspanid = name + 'delspan',
                showtext = text == undefined ? "" : text,
                temptype = options.type == undefined ? defaultsetting.type : options.type,
                placeholder = options.placeholder == undefined ? "请选择" : options.placeholder,
                imgclass = temptype == 'image' ? 'layui-img' : "",
                objname, html = [, '<div class = "layui-select-title" name="' + divname + '" >'],
                parenthtml = [, '<input type="hidden" class="layui-input" lay-verify="' + tempverify + '" name="' + inputhiddename + '" value="' + showvalue + '">'];
                defaultsetting.coltitle = options.multselect?checkboxType:radioType;
                // 设置分页
                if(!options.limit){
                    options.limit = 20;
                }
            if (url == undefined && sourcedata == undefined) {
                zlContext.errorMsg('未找到数据或数据源链接！')
                return;
            }

            $elem.attr('loaded', 1);
            if (temptype == 'text' || (temptype == 'image' && zlContext.isEmpty(showvalue))) {
                html.push('     <input type="text" class="layui-input" lay-verify="' + tempverify + '" placeholder ="' + placeholder + '"  name="' + inputname + '" readonly   value="' + showtext + '">');
                html.push('</div>');
            } else if (temptype == 'image') {
                html.push('     <img class="' + imgclass + '"  name="' + inputname + '" readonly   src="' + showtext + '">');

                html.push('</div>');
            }
            $elem.append(html.join(''));
            $parent.append(parenthtml.join(''));
            newoptions = $.extend({}, defaultsetting, options);
            if (newoptions.edittype == 'edit') {
                $('div[name="' + divname + '"]').append(' <i class="layui-icon layui-icon-more layui-i-add" id="' + addspanid + '"></i> ' + '     <i class="layui-icon layui-icon-close layui-i-del" id="' + delspanid + '"></i> ')
            }
            if (url == undefined) {
                newoptions.sourcedata = eval('(' + sourcedata + ')');
            }
            newoptions.type = temptype;
            newoptions.inputhiddename = inputhiddename;
            newoptions.inputname = inputname;
            newoptions.elemname = name;
            newoptions.params = eval('(' + newoptions.params + ')');


            if (zlContext.isEmpty(showtext) && !zlContext.isEmpty(showvalue)) {
                var tempvalue = showvalue;
                if (!zlContext.isEmpty(url)) {
                    newoptions.params[newoptions.id] = tempvalue;
                    $.ajax({
                        url: url,
                        type: newoptions.method,
                        async: true,
                        data: newoptions.params,
                        dataType: 'json',
                        success: function (result) {
                            var sourcedata = result.obj;
                            if (newoptions.type == 'image' && sourcedata.length > 0) {
                                $('img[name="' + newoptions.inputname + '"]').attr('src', layui.cache['contentPath'] + sourcedata[0][options.name]);
                            } else {
                                var objNames = [];
                                for (var i = 0; i < sourcedata.length; i++) {
                                    if (tempvalue.indexOf(sourcedata[i][newoptions.id]) > -1) {
                                        objNames.push(sourcedata[i][newoptions.name]);
                                    }
                                }
                                objname = objNames.join(",");
                                $('input[name="' + inputname + '"]').val(objname);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {

                        },
                        complete: function (XMLHttpRequest, textStatus) {}
                    });
                } else {
                    var objNames = [];
                    for (var i = 0; i < newoptions.sourcedata.length; i++) {
                        if (tempvalue.indexOf(newoptions.sourcedata[i][newoptions.id]) > -1) {
                            objNames.push((newoptions.sourcedata)[i][newoptions.name]);
                            if (newoptions.type == 'image') {
                                break;
                            }
                        }
                    }
                    objname = objNames.join(",");
                    if (newoptions.type == "image") {
                        $('img[name="' + inputname + '"]').attr('src', layui.cache['contentPath'] + objname);
                    } else {
                        $('input[name="' + inputname + '"]').val(objname);
                    }
                }
            }
            newoptions.params = eval('(' + (options.params) + ')');
            if (newoptions.edittype == 'edit') {
                zlPopSourceForm.initspans(newoptions, addspanid, delspanid, divname);
            }
        },
        initspans: function (options, addspanid, delspanid, divname, tempverify) {
            if (options.type == "image") {
                var $input = $('div[name="' + divname + '"]');
            } else {
                var $input = $('input[name="' + options.inputname + '"]');
            }

            $('#' + delspanid).hide();
            $input.on('mouseenter', function () {
                if (($(this).val() != "" && options.type != "image") || (options.type == 'image' && $input.find('img').length > 0)) {
                    $('#' + delspanid).show();
                }
            });
            $input.on('mouseleave', function () {
                $('#' + delspanid).hide();
            });
            $('#' + delspanid).on('mouseenter', function () {
                $('#' + delspanid).show();
            });
            $('#' + delspanid).on('mouseleave', function () {
                $('#' + delspanid).hide();
            });
            $('input[name="'+options.inputname+'"]').on('click',function(){
                $('#' + addspanid ).trigger('click');
            });
            $('#' + addspanid).on('click', function () {
                var objlist = new Array(),
                    zlInstance = null;
                var html = '<div class="layui-tab-item layui-show">' +
                '    <div id="searchBox" class="extSearchBox">' +
                '        <div class="layui-form-item extSearch-form-item">' +
                '            <div class="layui-input-block">' +
                '                <div id="showCondition"  class="extSearch-form-input-container">' +
                '                </div>' +
                '            </div>' +
                '            <div class="extSearch-form-input">' +
                '                <input type="text" class="simpleSearchInput" placeholder="请输入查找的值">' +
                '                <a href="javascript:;" class="simpleSearch">' +
                '                    <i class="layui-icon"></i>' +
                '                </a>' +
                '                <div id="searchIconBtn" class="searchIconBtn">' +
                '                    <a href="javascript:;" class="searchIconBtn-templeate">' +
                '                        <i class="layui-icon layui-icon-templeate-1"></i>' +
                '                    </a>' +
                '                    <a href="javascript:;" class="searchIconBtn-triangle">' +
                '                        <i class="layui-icon layui-icon-triangle-d" style="font-size: 12px;"></i>' +
                '                    </a>' +
                '                </div>' +
                '            </div>' +
                '        </div>' +
                '    </div>' +
                '    <div class="padding-lr zlpopform-table-box">' +
                '       <table id="tbFileres" class="layui-table" lay-filter="tbFileres"></table>' +
                '    </div>' +
                '</div>' 
                layer.open({
                    type: 1,
                    id: 'zlPopSourceFormCheckLayer',
                    area: ['600px', '80%'],
                    content: html,
                    title: options.formtitle == undefined ? "资源信息" : options.formtitle,
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        
                            var zlpopformTableBoxH = layero.find('div.layui-layer-content').height() - 48;
                            $(".zlpopform-table-box").css({height:zlpopformTableBoxH});
                            fileresTable = table.render({
                                elem: '#tbFileres',
                                response: zlConfig.global.gridResponse,
                                page: options.page,
                                cols: options.coltitle,
                                height: zlpopformTableBoxH-10,
                                method: options.method == undefined ? 'post' : options.method,
                                url: options.dataurl == undefined ? null : options.dataurl,
                                limit: options.limit,
                                limits:[options.limit,options.limit*2,options.limit*3,options.limit*4,options.limit*50],
                                data: options.sourcedata == undefined ? null : options.sourcedata,
                                where: options.params,
                                done: function (res, curr, count) {
                                    zlPopSourceForm.setcheck(res, options);
                                }
                            });

                            // IE浏览器 calc 兼容处理
                            if(zlContext.browserType() == 'IE'){
                                var pWidth = layero.find('div.extSearch-form-input').outerWidth(true),
                                    simpleSearchWidth = layero.find('a.simpleSearch').outerWidth(true),
                                    conditionSearchWidth = layero.find('div#searchIconBtn').outerWidth(true);
                                layero.find('input.simpleSearchInput').width(pWidth - simpleSearchWidth - conditionSearchWidth).css('box-sizing','border-box')

                            }
                            if(options.isOpenAdQ && options.isDynamic){
                                zlInstance = zlDynamicCondition.create({
                                    // fields: [{
                                    //     field: "WJZY_MINGC",
                                    //     title: "名称",
                                    //     edit: "text"
                                    // }, {
                                    //     field: "WJZY_BIANH",
                                    //     title: "编号",
                                    //     edit: "text"
                                    // }],
                                    strategyId: "#showCondition", // 查询策略 存放的 dom 选择器
                                    tableId: 'tbFileres',
                                    url: options.dataurl,
                                    shiycjid:options.shiycjid,
                                    page:options.page,
                                })
                                $('div#searchBox #searchIconBtn').on('click', function () {
                                    zlInstance.open();
                                });
                                $('div#searchBox input.simpleSearchInput').css('width','calc(100% - 68px)')
                            }else {
                                $('div#searchBox #searchIconBtn').hide();  
                                $('div#searchBox #showCondition').hide(); 
                            }
                            // 简单查询
                            layero.on('click','.simpleSearch',function(){
                                $('#showCondition').find('span.selected').removeClass('selected').css('background-color','#1e9fff')
                                var text = $(this).siblings('input').val();
                                isloadsearch = true;
                                simpleSearchhandle(text);
                                $('#showCondition').find('span.selected').removeClass('selected');
                            })
                            $('#zlPopSourceFormCheckLayer').on('keyup','.simpleSearchInput',function(e){
                                if (e.keyCode == "13") {
                                    var text = $(this).val();
                                    isloadsearch = true;
                                    simpleSearchhandle(text)
                                }
                                if ((e.keyCode == '46' || e.keyCode == '8' || (e.ctrlKey && e.keyCode == '86')) && $(this).val() == '' && isloadsearch) {
                                    $('.simpleSearch').trigger('click');
                                    isloadsearch = false;
                                }
                            })

                            function simpleSearchhandle(text){
                                if(!options.isOpenAdQ){
                                    if(totalCounts <= pageCounts){
                                        var totalCounts = layero.find('div.layui-table-page').find('span.layui-laypage-count').html().replace(/[^0-9]/ig, ""),
                                        pageCounts = layero.find('div.layui-table-page').find('span.layui-laypage-limits').find('option:selected').val();
                                        var trs = layero.find('div.layui-table-main').find('tr');
                                        trs.hide();
                                        layero.find('.noData').remove();
                                        layero.find('div.layui-table-page').show();
                                        for (var i = 0; i < trs.length; i++) {
                                            var tds = $(trs[i]).find('td');
                                            for (var k = 0; k < tds.length; k++) {
                                                var targetBox = $(tds[k]).children('div');
                                                if (targetBox.children().length == 0 && targetBox.html().includes(text)) {
                                                    $(trs[i]).show();
                                                    break;
                                                }
                                            }
                                        }
                                        if (layero.find('div.layui-table-main').find('tr:visible').length == 0) {
                                            layero.find('div.layui-table-main').append( '<div class="layui-none noData">' +
                                                                                        '    <div class="empty-data" style="text-align:center;padding-top: 10%;font-size: 25px;color: #ccc;font-family: tahoma ,微软雅黑;">' +
                                                                                        '        <i class="layui-icon layui-icon-search" style="font-size: 100px;"></i>   ' +
                                                                                        '        <div style="padding-top: 10px;">无数据</div>' +
                                                                                        '    </div>' +
                                                                                        '</div>');
                                            layero.find('div.layui-table-page').hide();
                                        }
                                    }else if(options.sourcedata){
                                        var newSourcedata = [];
                                        if(text != ""){
                                            $.each(options.sourcedata, function (k, item) {
                                                for (var key in item) {
                                                    var str = item[key];
                                                    if (typeof (str) == 'string' && str.indexOf(text) != -1) {
                                                        newSourcedata.push(item);
                                                    }
                                                }
                                            });
                                        }
                                        
                                        fileresTable.reload({
                                            data: (newSourcedata.length!=0 ? newSourcedata : options.sourcedata)
                                            ,page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        })
                                    } else {
                                        var newparam1 = $.extend({}, options.params, { SEARCHVALUE: text });
                                        fileresTable.reload({
                                            url: options.dataurl,
                                            where: newparam1
                                            , page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                    }
                                } else {
                                    var newparam = $.extend({}, options.params, { SEARCHVALUE: text });
                                    fileresTable.reload({
                                        url: options.dataurl,
                                        where: newparam
                                        , page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });
                                }
                            }

                            // 点击确定
                            // layero.on('click','#btnsure',function(){
                            //     var checkStatus = table.checkStatus('tbFileres'),
                            //         rows = checkStatus.data;
                            //     if (rows.length == 0) {
                            //         zlContext.errorMsg(options.errmsg == undefined ? "请选择记录" : options.errmsg);
                            //         return;
                            //     } else if ((!options.multselect) && rows.length > 1) {
                            //         zlContext.errorMsg("只能选择一个记录！");
                            //         return;
                            //     }
                            //     layer.close(index);
                            //     if (options.selectcallback != undefined) {
                            //         options.selectcallback(rows, options);
                            //     } else {
                            //         return rows;
                            //     }
                            // })
                        },
                        resizing: function (layero) {
                            var zlpopformTableBoxH = layero.find('div.layui-layer-content').height() - 48;
                            $(".zlpopform-table-box").css({height:zlpopformTableBoxH});
                            fileresTable.reload({
                                height: zlpopformTableBoxH-10,
                            });
                        },
                        yes: function (index, layero) {
                            var checkStatus = table.checkStatus('tbFileres'),
                                rows = checkStatus.data;
                            if (rows.length == 0) {
                                zlContext.errorMsg(options.errmsg == undefined ? "请选择记录" : options.errmsg);
                                return;
                            } else if ((!options.multselect) && rows.length > 1) {
                                zlContext.errorMsg("只能选择一个记录！");
                                return;
                            }
                            layer.close(index);
                            if (options.selectcallback != undefined) {
                                options.selectcallback(rows, options);
                            } else {
                                return rows;
                            }
                            zlPopSourceForm.$parentelem.trigger("afterselect",rows);
                        }

                });
            });
            $('#' + delspanid).on('click', function () {
                $('input[name="' + options.inputhiddename + '"]').val("");
                $('input[name="' + options.inputname + '"]').val("");
                zlPopSourceForm.$parentelem.trigger("afterselect",'');
                if (options.type == "image") {
                    var $img = $('img[name="' + options.inputname + '"]');
                    if ($img.length > 0) {
                        var html = '     <input type="text" class="layui-input"  name="' + options.inputname + '" readonly lay-verify="' + tempverify + '"  value="">',
                            $parent = $img.parent();
                        $img.remove();
                        $parent.prepend(html);
                    }
                }
            });
        },

        setcheck: function (res, defaultsetting) {
            if(defaultsetting.dataurl !=undefined){
                if (res.state != 'OK') {
                    return;
                }
                
            }
            res = res.obj;
            var ids = $('input[name="' + defaultsetting.inputhiddename + '"]').val();
            if (ids != undefined) {
                for (var i = 0; i < res.length; i++) {
                    if (ids.indexOf(res[i][defaultsetting.id]) > -1) {
                        res[i]['LAY_CHECKED'] = 'true';
                        var index = res[i]['LAY_TABLE_INDEX'];
                        if(!defaultsetting.multselect){
                            $('.layui-table-box').find('tr[data-index=' + index + '] input[type="radio"]').prop('checked', true);
                            $('.layui-table-box').find('tr[data-index=' + index + '] input[type="radio"]').addClass('layui-form-radioed');
                            $('.layui-table-box').find('tr[data-index=' + index + '] input[type="radio"]').addClass('layui-anim-scaleSpring');
                            layui.form.render();
                            return;
                        }else{
                            $('.layui-table-fixed-l tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                            $('.layui-table-fixed-l tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                        }
                        
                    }
                }
            }
            layui.form.render();
        },
        onlyShowForm: function ($elem) {
            var defaultsetting = {
                    coltitle: [
                        [{
                                type: 'numbers',
                                fixed: 'left',
                                title: '#'
                            },
                            {
                                type: 'checkbox',
                                fixed: 'left'
                            },
                            {
                                field: 'OBJNAME',
                                title: '名称',
                                width: 200
                            },
                            {
                                field: 'OBJCODE',
                                title: '编号',
                                width: 200
                            }
                        ]
                    ],
                    multselect: false,
                    page: false,
                    limit: 999,
                    selectcallback: function (data, options) {},
                },
                html = ['<div  class="layui-tab-item layui-show">', '<table id="tbFileres" class="layui-table"></table>', '</div>'],
                settings = ($elem.attr('settings') != "" ? eval('(' + $elem.attr('settings') + ')') : {});
                // 设置分页
                if(!settings.limit){
                    settings.limit = 20;    
                }
                var options = $.extend({}, defaultsetting, settings);
                $elem.on('click', function () {

                var objlist = new Array();
                layer.open({
                    type: 1,
                    id: 'zlPopSourceFormLayer',
                    area: ['600px', '80%'],
                    content: html.join(''),
                    title: options.formtitle == undefined ? "资源信息" : options.formtitle,
                    btn: ['确定', '取消'],
                    success: function () {
                        table.render({
                            elem: '#tbFileres',
                            response: zlConfig.global.gridResponse,
                            page: options.page,
                            cols: options.coltitle,
                            method: options.method == undefined ? 'post' : options.method,
                            url: options.dataurl == undefined ? null : options.dataurl,
                            limit: options.limit,
                            limits:[options.limit,options.limit*2,options.limit*3,options.limit*4,options.limit*5],
                            data: options.data == undefined ? null : data,
                            where: options.params,
                            done: function (res, curr, count) {
                                zlPopSourceForm.setcheck(res, options);
                            }
                        });
                    },
                    yes: function (index) {
                        var checkStatus = table.checkStatus('tbFileres'),
                            rows = checkStatus.data;
                        if (rows.length == 0) {
                            zlContext.errorMsg(options.errmsg == undefined ? "请选择记录" : options.errmsg);
                            return;
                        } else if ((!options.multselect) && rows.length > 1) {
                            zlContext.errorMsg("只能选择一个记录！");
                            return;
                        }
                        layer.close(index);
                        if (options.selectcallback != undefined) {
                            options.selectcallback(rows, options);
                        } else {
                            return rows;
                        }
                    },
                });
            });
        },
        showDeptUser: function ($elem, options) {
            var depttreeobj, usertreeobj;
            var deptdefaultsetting = {
                id: 'RWID',
                check: {
                    enable: false,
                    autoCheckTrigger: true,
                    chkboxType: {
                        "Y": "",
                        "N": ""
                    },
                    chkStyle: "checkbox",
                },
                view: {
                    showLine: true
                },
                async: {
                    enable: true,
                    url: layui.cache['contentPath'] + '/admin/bddept/querydeptuser',
                    type: "post",
                    dataFilter: function ajaxDataFilter(treeId, parentNode, responseData) {
                        if (responseData[zlConfig.global.result.statusName] == 'OK') {
                            var data = responseData[zlConfig.global.result.dataName];
                            return data;
                        } else {
                            zlContext.errorMsg(responseData[zlConfig.global.result.msgName]);
                        }
                        return responseData;
                    }
                },
                data: {
                    key: {
                        name: "OBJNAME"
                    },
                    simpleData: {
                        enable: true,
                        idKey: "RWID",
                        pIdKey: "SYS_PARENTID",
                        rootPid: ""
                    }

                },
                callback: {
                    onAsyncSuccess: function (event, treeId, treeNode, msg) {

                    },
                    onClick: function (event, treeId, treeNode) {
                        var rwid = treeNode['RWID'];
                        userfaultsetting.async.otherParam.DEPTID = rwid;
                        userfaultsetting.async.otherParam = $.extend({},userfaultsetting.async.otherParam, newoptions.async.otherParam);
                        usertreeobj = $.fn.zTree.init($("#userTreeId"), userfaultsetting, null);
                    },
                    beforeClick: function (treeId, treeNode, clickFlag) {
                        if (newoptions.ischeckleaf) {
                            return !treeNode.isParent; //当是父节点 返回false 不让选取
                        } else {
                            return true;
                        }

                    }
                }
            };
            var newoptions = $.extend({}, deptdefaultsetting, options);
            newoptions.async.otherParam = {
                ORGID: newoptions.ORGID
            };
            var userfaultsetting = {
                check: {
                    enable: true,
                    autoCheckTrigger: true,
                    chkboxType: {
                        "Y": "",
                        "N": ""
                    },
                    chkStyle: "checkbox",
                },
                view: {
                    showLine: true
                },
                async: {
                    enable: true,
                    url: layui.cache['contentPath'] + '/admin/coreuser/querydeptuser',
                    type: "post",
                    dataFilter: function ajaxDataFilter(treeId, parentNode, responseData) {
                        if (responseData[zlConfig.global.result.statusName] == 'OK') {
                            var data = responseData[zlConfig.global.result.dataName];
                            for (var i = 0; i < data.length; i++) {
                                data[i].icon = layui.cache['contentPath'] + "/static/image/role.png";
                            }
                            return data;
                        } else {
                            zlContext.errorMsg(responseData[zlConfig.global.result.msgName]);
                        }
                        return responseData;
                    },

                },
                data: {
                    key: {
                        name: "OBJNAME"
                    },
                    simpleData: {
                        enable: true,
                        rootPid: ""
                    }

                },
                callback: {}
            }
            if(options.userParam){
                userfaultsetting.async.otherParam  = options.userParam;
            }
            var html = ['<div class="layui-fluid" style="">', '    <div class="layui-row  layui-col-space5">', '        <div class="layui-col-md6 docking-left">', '            <div class="layui-card docking-left" style="height:485px;">', '                <div class="layui-card-header" style="height:20px;line-height:14px">部门</div>', '                <div class="layui-card-body">', '                    <ul id="orgTreeId" class="ztree" style="overflow-x:hidden;height:430px"></ul>', '                </div>', '            </div>', '        </div>', '        <div class="layui-col-md6 docking-fill">', '            <div class="layui-card docking-left" style="height:485px;">', '                <div class="layui-card-header" style="height:20px;line-height:14px">人员</div>', '                <div class="layui-card-body">', '                    <ul id="userTreeId" class="ztree" style="overflow-x:hidden;height:430px" ></ul>', '                </div>', '            </div>', '        </div>', '    </div>', '</div>'];
            layer.open({
                type: 1,
                id:'zlPopSourceFormChooseLayer',
                area: ['600px', '80%'],
                content: html.join(''),
                title: newoptions.formtitle == undefined ? "选择部门人员" : newoptions.formtitle,
                btn: ['确定', '取消'],
                resize: false,
                success: function () {
                    depttreeobj = $.fn.zTree.init($("#orgTreeId"), newoptions, null);
                },
                yes: function (index) {
                    var selectnode = usertreeobj.getCheckedNodes(true);
                    if (selectnode.length == 0) {
                        zlContext.warnMsg('请选择人员！');
                        return;
                    }
                    var data = new Array;
                    var seledept = depttreeobj.getSelectedNodes();
                    data.push(seledept);
                    data.push(selectnode);
                    layer.close(index);
                    if (newoptions.selectcallback != undefined) {
                        newoptions.selectcallback(data);
                        return;
                    }
                    return data;
                }
            });
        }
    }
    exports('zlPopSourceForm', zlPopSourceForm);
});